<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <%--   功能按钮 --%>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">
                            <button class="btn btn-sm btn-info" id="query">条件搜索</button>
                            <button class="btn btn-sm btn-default" id="edit">编辑</button>
                            <button class="btn btn-sm btn-success" id="create">新增</button>
                            <button class="btn btn-sm btn-danger" id="delete">删除</button>
                        </div>
                    </div>
                </div>
                <%--   数据表格         --%>
                <div class="row">
                    <div class="col-xs-12">
                        <table id="gridTable"></table>
                        <div id="gridPager"></div>
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<!-- dialog -->
<%@ include file="/WEB-INF/views/include/dialog.jsp" %>
<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/common/smsTemplate"></s:url>/"
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['', '模板CODE', '模板类型', '模板标题', '模板内容', '模板json','操作'];
    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'templateCode', index: 'templateCode', width: 160, editable: true},
        {name: 'templateType', index: 'templateType', width: 160, editable: true,formatter: templateTypeFormatter},
        {name: 'templateName', index: 'templateName', width: 160, editable: true},
        {name: 'templateContent', index: 'templateContent', width: 160, editable: true},
        {name: 'templateJson', index: 'templateJson', width: 160, editable: true},
        {name : 'caozuo', width : 150, align : "center",formatter:feedbackBtnFormatter }
    ];


    function feedbackBtnFormatter(value, grid, rows, state) {
        console.log(value, grid, rows, state);
        grid.colModel.title=false
        return "<div style='color: #049CE6;display: flex;justify-content: center'>" +
            "<div style='width: 40px;cursor: pointer' title='查看'id='feedbackBtn'>测试</div>" +
            // "<div style='border-left:1px solid #049CE6;border-right:1px solid #049CE6;width: 40px;cursor: pointer'title='修改'>修改</div>" +
            // "<div style='width: 40px;cursor: pointer' title='删除'>删除</div>" +
            "</div>";
    }
    /**
     * 模板类型   格式化
     * 1短信 2邮件 3微信
     */
    function templateTypeFormatter(data) {
        switch(data) {
            case '1':
                return '短信模板';
                break;
            case '2':
                return '邮件模板';
                break;
            case '3':
                return '微信模板';
            default:
                return '-';
        }
    }
    /**
     * 推送状态   格式化
     * 0未推送 1推送成功 2推送失败
     */
    function esSendStatusFormatter(data) {
        switch(data) {
            case '0':
                return '未推送 ';
                break;
            case '1':
                return '推送成功';
                break;
            case '2':
                return '推送失败';
                break;
            default:
                return '-';
        }
    }
    var rowIds;
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }
    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }
    //jqgrid的具体执行方法
    jqgrid({
        shrinkToFit: false,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        autoScroll: false,
        shrinkToFit: false,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid
            var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
            var type = selectedRowValue.templateType; //推送方式
            console.log('当前推送方式：'+ type)
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i< rowids.length; i++){
                    if(rowids[i] ==  rowid){
                        flag = true;
                        continue;
                    }
                }
                if(!flag){
                    gridAddSelect(rowid);
                }
            }
        },
        ondblClickRow:function (rowid) {
            console.log('db  click')
        }
    });

    //加载查询对话框
    $("#queryDialog").load(getUrl("filter"));
    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }
    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        showDialog({
            dialogTitle: '条件搜索',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
                "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
                "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });


    //更新操作
    $("#edit").click(function () {
        showEditView();
    });
    //显示编辑对话框
    function showEditView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: getUrl("edit"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn" >更新</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    //删除
    $("#delete").click(function () {
        showDeleteView();
    });

    //显示删除对话框
    function showDeleteView() {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    }

    //显示创建对话框
    $("#create").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("create"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()" disabled id="create-template-btn">创建模板</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            //failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }


    $("#gridTable").dblclick(function (e) {
       // showView();
    });




</script>
</body>
</html>
